package com.cff.pm.handler;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.cff.pm.client.HttpSpider;
import com.cff.pm.common.Constant;
import com.cff.pm.dto.PmUser;

import okhttp3.OkHttpClient;

public class LoginHandler {
	HttpSpider httpSpider;
	
	public boolean login(PmUser user) {
		if(httpSpider == null) return false;
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("account", user.getUserName());
		paramMap.put("password", user.getPasswd());
		paramMap.put("keepLogin[]", "on");
		paramMap.put("referer", "http://pm.shangdejigou.cn/my/");
		
		try {
			String res = httpSpider.doPostWithJsonResult(Constant.LOGIN_URL, paramMap);
			if(res.contains("登录失败"))return false;
			return true;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}

	public HttpSpider getHttpSpider() {
		return httpSpider;
	}

	public void setHttpSpider(HttpSpider httpSpider) {
		this.httpSpider = httpSpider;
	}
}
